package com.ftg.learn.bus.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ftg.learn.bus.VO.busUseRegidtrationVo;
import com.ftg.learn.bus.entity.BusUseRegistration;
import com.ftg.learn.bus.service.IBusUseRegistrationService;
import com.ftg.learn.util.ResEntity;
import com.ftg.learn.util.ResPageEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 公车使用登记表 前端控制器
 * </p>
 *
 * @author LSY
 * @since 2022-03-21
 */
@RestController
@RequestMapping("/bus/bus-use-registration")
@Api(tags = "公车使用登记管理功能列表")
public class BusUseRegistrationController extends CrudpController<BusUseRegistration, IBusUseRegistrationService> {

    @Resource
    IBusUseRegistrationService iBusUseRegistrationService;

    @PutMapping("/insertAuto")
    @ApiOperation(value = "添加公车使用登记")
    ResEntity insertOner(@RequestParam Long bid, @RequestParam String user_name, @RequestParam String user_phone,
                         @RequestParam String start_place, @RequestParam String end_place,
                         @RequestParam String end_mileage,
                         @RequestParam String borrow_time,
                         @RequestParam String is_special, @RequestParam String actual_purpose
    ){
        return iBusUseRegistrationService.insertInfor(bid,user_name,user_phone,start_place,end_place,end_mileage,
                borrow_time,is_special,actual_purpose)
                ? new ResEntity().OK() : new ResEntity().Failure();
    }

    @GetMapping("/selectByIdI/{burid}")
    @ApiOperation(value = "按公车id查使用信息")
    ResEntity selectById1(@PathVariable("burid") Long burid){
        return new ResEntity(0,"success", iBusUseRegistrationService.selectById1(burid));
    }

    @GetMapping("/busShowByName/{bus_name}")
    @ApiOperation(value = "根据公车名进行查询")
    public ResEntity busShowByName(@PathVariable("bus_name") String bus_name){
        return new ResEntity(0,"success",super.service.busShowByName(bus_name));
    }

    @GetMapping("/showBusName")
    @ApiOperation(value = "分页功能")
    public ResPageEntity showBusName(@RequestParam int page, @RequestParam int limit, @RequestParam String bus_name){
        Page<BusUseRegistration> pagination = new Page<>(page,limit);
        pagination.setRecords(super.service.showBusName(pagination,bus_name));
        return new ResPageEntity(pagination);
    }


    @GetMapping("/showBusNamePage")
    @ApiOperation(value = "首页分页功能")
    public ResPageEntity showBusNamePage(@RequestParam int page, @RequestParam int limit){
        Page<busUseRegidtrationVo> pagination = new Page<>(page,limit);
        pagination.setRecords(super.service.showBusNamePage(pagination));
        return new ResPageEntity(pagination);
    }

    @GetMapping("/showAllName")
    @ApiOperation(value = "查询全部车辆bid,bus_name")
    public ResEntity showAllName() {
        return new ResEntity(0, "success", super.service.showAllName());
    }

}
